package cn.bb.service;

import cn.bb.dao.IUserDao;
import cn.bb.pojo.Page;
import cn.bb.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service("userService")
public class IUserServiceImpl implements IUserService {
    @Autowired
    private IUserDao userDao;
    @Override
    public Page queryLikeUsers(Map<String, Object> map) {
        Page page = new Page();
        int i = userDao.getLikeUsersCount(map);
        //获得总记录数
        page.setTotalNum(i);
        //每页的页数
        int pageSize = Integer.parseInt(String.valueOf(map.get("pageSize")));
        page.setPageSize(pageSize);
        //当前页数
        page.setCurPageNum(Integer.parseInt(String.valueOf(map.get("currentPage"))));
        //动态计算总页数
        page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize ==0?0:1));
        //查询列表
        page.setResult(userDao.getLikeUsers(map));
        return page;
    }

    /**
     * 增加用户
     * @param user
     * @return
     */
    @Override
    public int addUsers(User user) {
        return userDao.addUser(user);
    }

    @Override
    public User UserDetail(User user) {
        return userDao.getDetailById(user);
    }

    @Override
    public int updateUsers(User user) {
        return userDao.updateUserInfo(user);
    }

    @Override
    public int deleteDao(User user) {
        return userDao.delteUserInfo(user);
    }


    public IUserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(IUserDao userDao) {
        this.userDao = userDao;
    }
}
